USE NutritionTracker
GO
IF EXISTS (SELECT 1 FROM sysobjects WHERE ID = object_id(N'AppUser_Update_Item') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
	DROP PROCEDURE AppUser_Update_Item
GO
CREATE PROC AppUser_Update_Item
(
@AppUserID	INT,
@FirstName	NVARCHAR(25),
@LastName	NVARCHAR(25),
@EmailAddress	NVARCHAR(25),
@Password	VARCHAR(50),
@TimeZoneOffset	TINYINT = NULL,
@Approved	BIT = 1,
@UpdatePassword	BIT = 0,
@Deleted	BIT = 0
)
AS
BEGIN
	SET NOCOUNT ON

	UPDATE		AppUser
	SET		FirstName = NULLIF(RTRIM(LTRIM(@FirstName)),''),
			LastName = NULLIF(RTRIM(LTRIM(@LastName)),''),
			EmailAddress = 	NULLIF(RTRIM(LTRIM(@EmailAddress)),''),
			[Password] = NULLIF(RTRIM(LTRIM(@Password)),''),
			TimeZoneOffset = @TimeZoneOffset,
			Approved = @Approved,
			UpdatePassword = @UpdatePassword,
			Deleted = @Deleted
	WHERE		AppUserID = @AppUserID
	
	SET NOCOUNT OFF
END
GO
GRANT EXECUTE ON AppUser_Update_Item TO NUTRKR_WEB
GO
